import java.awt.Graphics2D;
import java.util.List;

import com.golden.gamedev.GameEngine;
import com.golden.gamedev.GameObject;

/**
 * 
 * @author djs22
 *
 * GameFlow is responsible for running the game itself. 
 */
public abstract class GameFlow extends GameObject {
    
	/**
	 * States whether or not currentScene is running
	 */
    protected boolean running;
    
    /**
     * The name of the next scene to run
     */
    protected String nextSceneName;
    
    /**
     * The current scene that is being displayed/ran.
     */
    protected Scene currentScene;
    protected List<Object> params;
    protected Class paramClass;
    
    public GameFlow(GameEngine parent){
        super(parent);
    }
    
    /**
     * Responsible for choosing the correct scene to update and then updating it.
     */
    public void update(long elapsedTime){
        
        if(!running){
            if(nextSceneName == null){
                this.finish();
            }
            currentScene = getScene(nextSceneName,params);
            running = true;
            nextSceneName = null;
        }
        
        currentScene.update(elapsedTime); 
        
    }
    
    /**
     * Tells the current scene to update.
     */
    public void render(Graphics2D g){
        currentScene.render(g);
    }
    
    /**
     * Gets a scene given a scene name. 
     * Extensions of GameFlow need to implement a default behavior for converting a String of scene name and param into a Scene.
     * @param sceneName
     * @return
     */
    protected abstract Scene getScene(String sceneName,List<Object> params);
    
    
    /**
     * Closes the current scene, declares which scene to instatiate next and how to do it. 
     * @param nextSceneName
     * @param params
     */
    public void endScene(String nextSceneName,List<Object> params){
        running=false;
        this.nextSceneName = nextSceneName;
        this.params=params;
    }
    
    
}
